package org.jeecg.modules.flowable.common.util;


import org.jeecg.modules.flowable.common.util.id.SnowflakeIdWorker;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

/**
 * Title:  <br>
 * Desc:  <br>
 * Date: 2020-07-11 13:04 <br>
 * Company: 联通（辽宁）产业互联网有限公司 <br>
 *
 * @author zxd
 * @version 1.0.0
 */
public class IdUtil {

    /**
     * 工作组ID
     */
    public static int workerId = 1;
    /**
     * 数据中心ID
     */
    public static int datacenterId = 1;

    private static Map<Integer, SnowflakeIdWorker> _map = null;

    private static void _init() {
        if (_map == null || _map.size() == 0) {
            _map = new HashMap<>();
            _map.put(0, new SnowflakeIdWorker(workerId, datacenterId));
        }
    }

    public static String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static Long getLongId() {

        _init();
        return _map.get(0).nextId();
    }

    private static int getRandom(int min, int max) {
        Random random = new Random();
        int s = random.nextInt(max) % (max - min + 1) + min;
        return s;
    }

    private static int[] getConVal(int argNum) {
        int[] arr = new int[2];
        int i = argNum;
        int max = 31;
        int a = 0;
        int b = 0;
        if (i > 31)
            a = i / max;
        b = i - max * a;
        arr[0] = a;
        arr[1] = b;
        return arr;
    }

    public static String getStringId() {
        return getLongId().toString();
    }

}